<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%response.setHeader("cache-control","public"); %>
<%
    String path = request.getContextPath();
    application.setAttribute("path",path);
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<!-- 人员管理列表 -->
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/common.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/style.default.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/bootstrap-table.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/jstreeview/plugins/bootstrap-dialog/bootstrap-dialog.min.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/examMng/paperMng.css">
      <!--bootstrap基础引用 start-->
    <script type="text/javascript" src="<%=path%>/static/jstreeview/bootstrap/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="<%=path%>/static/jstreeview/bootstrap/bootstrap.min.js"></script>
    <!--bootstrap基础引用 end-->
    <!--bootstrap-dialog start-->

    <script type="text/javascript" src="<%=path%>/static/jstreeview/plugins/bootstrap-dialog/bootstrap-dialog.min.js"></script>
    <!--bootstrap-dialog end-->
        <script type="text/javascript" src="<%=path%>/static/js/jquery-1.9.1.min.js"></script>
        <link rel="stylesheet" type="text/css" href="<%=path%>/static/select/bootstrap-select.css">
    </head>
<body>

<jsp:include page="../head.jsp" flush="true"/>

<!--body begin-->
<div class="main-container">
    <div class="body-box container" style="padding: 0px;">
        <div class="title-top" style="background: #4c4ca6">
            <p>人员列表：</p>
            <a class="btn btn-success addpaper" href="<%=path%>/person/pagedata" style="background: #4c4ca6;border:solid 1px #ffffff; "><i
                    class="glyphicon glyphicon-plus-sign" ></i>新增人员</a>
        </div>
        <div class="paper-content">
            <!--当前没有可用试卷 end-->
            <div class="content">
                <div class="table-responsive">
                    <div id="toolbar">
                        <select id="unitAjax" class="selectpicker" multiple data-live-search="true" title="请选择单位">
                        </select>
                        <select id="proAjax" class="selectpicker" multiple data-live-search="true" title="请选择专业">
                        </select>
                        <select id="rankAjax" class="selectpicker" multiple data-live-search="true" title="请选择级别">
                        </select>
                        <button id="search" type="button" onclick="searchAjax()" class="btn dropdown-toggle btn-default" style="position: relative;top:-5px;">
                            <span class="glyphicon glyphicon-search"></span>
                        </button>
                    </div>
                    <table id="taskList_table" class="table-striped table-hover"
                           data-mobile-responsive="true"></table>
                </div>
            </div>
            <!--试卷列表-->
            <table id="table"></table>
        </div>
    </div>
</div>
<!--body end-->
</div>
<!--footer end-->
<script type="text/javascript" src="<%=path%>/static/js/bootstrap-table.js"></script>
<script type="text/javascript" src="<%=path%>/static/js/bootstrap-table-zh-CN.js"></script>
<script type="text/javascript" src="<%=path%>/static/select/bootstrap-select.js"></script>
</body>

<script type="text/javascript">

    $(function () {
        $.post("${path}/person/selectAjax",function (data) {
            var units = data.units;
            for (var i = 0; i < units.length; i++) {
                $("#unitAjax").append("<option value=\""+units[i].id+"\">"+units[i].name+"</option>");
            }
            var ranks = data.ranks;
            for (var i = 0; i < ranks.length; i++) {
                $("#rankAjax").append("<option value=\""+ranks[i].id+"\">"+ranks[i].name+"</option>");
            }
            var pros = data.pros;
            for (var i = 0; i < pros.length; i++) {
                $("#proAjax").append("<option value=\""+pros[i].id+"\">"+pros[i].name+"</option>");
            }
            $('#unitAjax').selectpicker('refresh');
            $('#unitAjax').selectpicker('render');
            $('#rankAjax').selectpicker('refresh');
            $('#rankAjax').selectpicker('render');
            $('#proAjax').selectpicker('refresh');
            $('#proAjax').selectpicker('render');
        })
        //人员管理 主页面
        if (${role eq 'master'}) {
            $('#topMain').children().eq(0).addClass('active'); // 追加样式;
            $('#topMain').children().eq(0).children().attr('href', '#');
        } else if (${role eq 'trainee'}) {
            $('#topMain').children().eq(0).addClass('active'); // 追加样式;
            $('#topMain').children().eq(0).children().attr('href', '#');
        } else {
            $('#topMain').children().eq(0).addClass('active'); // 追加样式;
            $('#topMain').children().eq(0).children().attr('href', '#');
        }
    })

    function searchAjax() {
        var unitId = $('#unitAjax').selectpicker('val');
        var proId = $('#proAjax').selectpicker('val');
        var rankId = $('#rankAjax').selectpicker('val');
        var unitIds = "";
        if (unitId != null) {
            unitIds = unitId.join(",");
        }

        var proIds = "";
        if (proId != null) {
            proIds = proId.join(",");
        }

        var rankIds = "";
        if (rankId != null) {
            rankIds = rankId.join(",");
        }
        console.info(unitId);
        console.info(proId);
        console.info(rankIds);
        $('#table').bootstrapTable('refresh', {
            method : 'psot',
            dataType : 'json',
            contentType : "application/x-www-form-urlencoded",
            url: "<%=path%>/person/searchAjax?unitIds="+unitIds+"&proIds="+proIds+"&rankIds="+rankIds,
            cache : false,
        });

    }

    function AddFunctionAlty(value, row, index) {

        if (row.account!="admin") {
            return [
                '<button id="edit",type="button" class="btn btn-default">编辑</button>&nbsp;' +
                '<button id="del",type="button" class="btn btn-default">删除</button>'
            ].join("")
        }
    }

    window.operateEvents = {
        'click #edit': function (e, value, row, index) {
            window.location.href = "<%=path%>/person/pagedata?id=" + row.id;

        }, 'click #del': function (e, value, row, index) {
        	BootstrapDialog.confirm({
				title : '提示',
				message : '确定删除此人员?',
				size : BootstrapDialog.SIZE_SMALL,
				type : BootstrapDialog.TYPE_DEFAULT,
				closable : true,
				btnCancelLabel : '取消',
				btnOKLabel : '确定',
				callback : function(result) {
					if(result){
                     $.ajax({
                            type:"post",
                            data:{userId:row.id},
                            url:"<%=path%>/person/findByUserId",
                            success:function (data) {
                                if(data){
                                    $.ajax({
                                        type: "post",
                                        data: row,
                                        url: '<%=path%>/person/del',
                                        success: function (data) {
                                            BootstrapDialog.confirm({
                                                title : '提示',
                                                message : '删除成功',
                                                size : BootstrapDialog.SIZE_SMALL,
                                                type : BootstrapDialog.TYPE_DEFAULT,
                                                closable : true,
                                                btnCancelLabel : '取消',
                                                btnOKLabel : '确定'
                                            });
                                            $('#table').bootstrapTable('refresh', {
                                                method : 'get',
                                                dataType : 'json',
                                                contentType : "application/x-www-form-urlencoded",
                                                url: "<%=path%>/person/dataList",
                                                cache : false,
                                            });
                                        }
                                    });
                                }else{
                                    BootstrapDialog.confirm({
                                        title : '提示',
                                        message : '该人员在考试中无法删除',
                                        size : BootstrapDialog.SIZE_SMALL,
                                        type : BootstrapDialog.TYPE_DEFAULT,
                                        closable : true,
                                        btnCancelLabel : '取消',
                                        btnOKLabel : '确定'
                                    });
                                }
                            }
                        })
					}
				}
			});
        }
    };

    $('#table').bootstrapTable({
        "pagination": true,
        method: 'post',
        dataType: 'json',
        contentType: "application/x-www-form-urlencoded",
        url: '/examsys/person/dataList',
        striped: true,
        toolbar: "#toolbar",
        showHeader: true,
        pageNumber: 1,
        pagination : true,//是否分页
		sidePagination : 'client',//server:服务器端分页|client：前端分页
		pageSize : 5,//单页记录数
		pageList : [ 5, 10, 20, 30 ],//可选择单页记录数
        columns: [{
            field: 'number',
            title: '序号',
            align: "center",
            valign: "middle",
            formatter: function (value, row, index) {
                return index + 1;
            }
        }, {
            field: 'identifier',
            title: '编号',
            align: "center",
            valign: "middle",
          	//是否启用排序
			sortable: true,  
			//排序方式
			sortOrder: "desc",
        }, {
            field: 'name',
            title: '姓名',
            align: "center",
            valign: "middle",
            //是否启用排序
            sortable: true,
            //排序方式
            sortOrder: "asc",
        }, {
            field: 'unit',
            title: '单位',
            align: "center",
            valign: "middle",
            //是否启用排序
            sortable: true,
            //排序方式
            sortOrder: "asc"
        }, {
            field: 'role',
            title: '角色',
            align: "center",
            valign: "middle",
            //是否启用排序
            sortable: true,
            //排序方式
            sortOrder: "asc",
        }, {
            field: 'account',
            title: '账号',
            align: "center",
            valign: "middle"
        }, {
            field: 'Operations',
            title: '操作',
            events: 'operateEvents',
            formatter: 'AddFunctionAlty',
            align: "center",
            valign: "middle"
        }]
    });

</script>

</html>

